  /******************************************************************************
  * @file    PT32X005_exti.c
  * @author  应用开发团队
  * @version V1.1.0
  * @date    2020/2/14
  * @brief    This file provides firmware functions to manage the functionality of EXTI peripherals
  *
  ******************************************************************************
  * @attention
  *
  *
  *****************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "PT32X005_exti.h"


/** @defgroup EXTI
  * @brief EXTI driver modules
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Enables or disables the specified exti interrupts.
  * @param  EXTIx: where x can be (A, B, C, D, E or F) to select the EXTI peripheral.
  * @param  EXTI_IT: specifies the EXTI interrupt sources to be enabled or disabled.
  *          This parameter can be one of the following values:
  *            @arg EXTI_IT_0  specifies the interrupt source for EXTIx0 interrupt
  *            @arg EXTI_IT_1  specifies the interrupt source for EXTIx1 interrupt
  *            @arg EXTI_IT_2  specifies the interrupt source for EXTIx2 interrupt
  *            @arg EXTI_IT_3  specifies the interrupt source for EXTIx3 interrupt
  *            @arg EXTI_IT_4  specifies the interrupt source for EXTIx4 interrupt
  *            @arg EXTI_IT_5  specifies the interrupt source for EXTIx5 interrupt
  *            @arg EXTI_IT_6  specifies the interrupt source for EXTIx6.interrupt
  *            @arg EXTI_IT_7  specifies the interrupt source for EXTIx7 interrupt
  *            @arg EXTI_IT_8  specifies the interrupt source for EXTIx8 interrupt
  *            @arg EXTI_IT_9  specifies the interrupt source for EXTIx9 interrupt
  *            @arg EXTI_IT_10 specifies the interrupt source for EXTIx10 interrupt
  *            @arg EXTI_IT_11 specifies the interrupt source for EXTIx11 interrupt
  *            @arg EXTI_IT_12 specifies the interrupt source for EXTIx12 interrupt
  *            @arg EXTI_IT_13 specifies the interrupt source for EXTIx13 interrupt
  *            @arg EXTI_IT_14 specifies the interrupt source for EXTIx14 interrupt
  *            @arg EXTI_IT_15 specifies the interrupt source for EXTIx15 interrupt
  *            @arg EXTI_IT_All specifies the interrupt source for All interrupt
  * @param  NewState: new state of the specified EXTI interrupts.
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void EXTI_ITConfig(EXTI_TypeDef* EXTIx, u32 EXTI_IT, FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_EXTI_ALL_PERIPH(EXTIx));
	assert_param(IS_EXTI_IT_SEL(EXTI_IT));
	assert_param(IS_FUNCTIONAL_STATE(NewState));
	if (NewState != DISABLE)
	{
		EXTIx->IES |= EXTI_IT;
	}
	else
	{
		EXTIx->IEC |= EXTI_IT;
	}
}


/**
  * @brief Exti interrupts trigger types configuration
  * @param  EXTIx: where x can be (A, B, C, D, E or F) to select the EXTI peripheral.
  * @param  EXTI_Pin: specifies the port bit to be written.
  *            @arg EXTI_Pin_0    Port interrupt pending bit set, bit 0
  *            @arg EXTI_Pin_1    Port interrupt pending bit set, bit 1
  *            @arg EXTI_Pin_2    Port interrupt pending bit set, bit 2
  *            @arg EXTI_Pin_3    Port interrupt pending bit set, bit 3
  *            @arg EXTI_Pin_4    Port interrupt pending bit set, bit 4
  *            @arg EXTI_Pin_5    Port interrupt pending bit set, bit 5
  *            @arg EXTI_Pin_6    Port interrupt pending bit set, bit 6
  *            @arg EXTI_Pin_7    Port interrupt pending bit set, bit 7
  *            @arg EXTI_Pin_8    Port interrupt pending bit set, bit 8
  *            @arg EXTI_Pin_9    Port interrupt pending bit set, bit 9
  *            @arg EXTI_Pin_10   Port interrupt pending bit set, bit 10
  *            @arg EXTI_Pin_11   Port interrupt pending bit set, bit 11
  *            @arg EXTI_Pin_12   Port interrupt pending bit set, bit 12
  *            @arg EXTI_Pin_13   Port interrupt pending bit set, bit 13
  *            @arg EXTI_Pin_14   Port interrupt pending bit set, bit 14
  *            @arg EXTI_Pin_15   Port interrupt pending bit set, bit 15
  *            @arg EXTI_Pin_All   Port interrupt pending bit set, All
  * @param  Trigger_Type: specifies trigger type.
  *            @arg EXTI_Trigger_Rising
  *            @arg EXTI_Trigger_Falling
  *            @arg EXTI_Trigger_Rising_Falling
  *            @arg EXTI_Trigger_High_Level
  *            @arg EXTI_Trigger_Low_Level
  * @retval None
  */
void EXTI_TriTypeConfig(EXTI_TypeDef* EXTIx, u32 EXTI_Pin, u32 Trigger_Type)
{
	/* Check the parameters */
	assert_param(IS_EXTI_ALL_PERIPH(EXTIx));
	assert_param(IS_EXTI_PIN_SEL(EXTI_Pin));
	assert_param(IS_EXTI_Trigger_SEL(Trigger_Type));
	switch( Trigger_Type )
	{
		case EXTI_Trigger_Rising :
			EXTIx->ITS = EXTI_Pin;
			EXTIx->PTS =  EXTI_Pin;
			EXTIx->ITDC = EXTI_Pin;
			break;
		case EXTI_Trigger_Falling :
			EXTIx->ITS = EXTI_Pin;
			EXTIx->PTC =  EXTI_Pin;
			EXTIx->ITDC = EXTI_Pin;
			break;
		case EXTI_Trigger_Rising_Falling :
			EXTIx->ITDS = EXTI_Pin;
			break;
		case EXTI_Trigger_High_Level :
			EXTIx->ITC = EXTI_Pin;
			EXTIx->PTS =  EXTI_Pin;
			EXTIx->ITDC = EXTI_Pin;
			break;
		case EXTI_Trigger_Low_Level :
			EXTIx->ITC = EXTI_Pin;
			EXTIx->PTC =  EXTI_Pin;
			EXTIx->ITDC = EXTI_Pin;

			break;
	}
}


/**
  * @brief  Clears the EXTI's pending flags.
  * @param  EXTIx: where x can be (A, B, C, D, E or F) to select the EXTI peripheral.
  * @param  EXTI_IT_FLAG: specifies the flag to clear.
  *          This parameter can be any combination of the following values:
  *            @arg EXTI_IT_0  specifies the interrupt source for EXTIx0 interrupt
  *            @arg EXTI_IT_1  specifies the interrupt source for EXTIx1 interrupt
  *            @arg EXTI_IT_2  specifies the interrupt source for EXTIx2 interrupt
  *            @arg EXTI_IT_3  specifies the interrupt source for EXTIx3 interrupt
  *            @arg EXTI_IT_4  specifies the interrupt source for EXTIx4 interrupt
  *            @arg EXTI_IT_5  specifies the interrupt source for EXTIx5 interrupt
  *            @arg EXTI_IT_6  specifies the interrupt source for EXTIx6.interrupt
  *            @arg EXTI_IT_7  specifies the interrupt source for EXTIx7 interrupt
  *            @arg EXTI_IT_8  specifies the interrupt source for EXTIx8 interrupt
  *            @arg EXTI_IT_9  specifies the interrupt source for EXTIx9 interrupt
  *            @arg EXTI_IT_10 specifies the interrupt source for EXTIx10 interrupt
  *            @arg EXTI_IT_11 specifies the interrupt source for EXTIx11 interrupt
  *            @arg EXTI_IT_12 specifies the interrupt source for EXTIx12 interrupt
  *            @arg EXTI_IT_13 specifies the interrupt source for EXTIx13 interrupt
  *            @arg EXTI_IT_14 specifies the interrupt source for EXTIx14 interrupt
  *            @arg EXTI_IT_15 specifies the interrupt source for EXTIx15 interrupt
  *            @arg EXTI_IT_All specifies the interrupt source for All interrupt
  * @retval None
  */
void EXTI_ClearFlag(EXTI_TypeDef* EXTIx, u32 EXTI_IT_FLAG)
{
	/* Check the parameters */
	assert_param(IS_EXTI_ALL_PERIPH(EXTIx));
	assert_param(IS_EXTI_IT_SEL(EXTI_IT_FLAG));
	EXTIx->IF |= EXTI_IT_FLAG;
}

/**
  * @brief  Checks whether the specified EXTI IT is set or not.
  * @param  EXTIx: where x can be (A, B, C, D, E or F) to select the EXTI peripheral.
  * @param  EXTI_IT: specifies the flag to get.
  *            @arg EXTI_IT_0  specifies the interrupt source for EXTIx0 interrupt
  *            @arg EXTI_IT_1  specifies the interrupt source for EXTIx1 interrupt
  *            @arg EXTI_IT_2  specifies the interrupt source for EXTIx2 interrupt
  *            @arg EXTI_IT_3  specifies the interrupt source for EXTIx3 interrupt
  *            @arg EXTI_IT_4  specifies the interrupt source for EXTIx4 interrupt
  *            @arg EXTI_IT_5  specifies the interrupt source for EXTIx5 interrupt
  *            @arg EXTI_IT_6  specifies the interrupt source for EXTIx6.interrupt
  *            @arg EXTI_IT_7  specifies the interrupt source for EXTIx7 interrupt
  *            @arg EXTI_IT_8  specifies the interrupt source for EXTIx8 interrupt
  *            @arg EXTI_IT_9  specifies the interrupt source for EXTIx9 interrupt
  *            @arg EXTI_IT_10 specifies the interrupt source for EXTIx10 interrupt
  *            @arg EXTI_IT_11 specifies the interrupt source for EXTIx11 interrupt
  *            @arg EXTI_IT_12 specifies the interrupt source for EXTIx12 interrupt
  *            @arg EXTI_IT_13 specifies the interrupt source for EXTIx13 interrupt
  *            @arg EXTI_IT_14 specifies the interrupt source for EXTIx14 interrupt
  *            @arg EXTI_IT_15 specifies the interrupt source for EXTIx15 interrupt
  * @retval ITStatus:interrupts status,the value can be 'SET' or 'RESET'.
  */
ITStatus EXTI_GetITStatus(EXTI_TypeDef* EXTIx, u32 EXTI_IT)
{
	ITStatus bitstatus = RESET;
	u32 enablestatus = 0;
	/* Check the parameters */
	assert_param(IS_EXTI_ALL_PERIPH(EXTIx));
	assert_param(IS_EXTI_IT_GET(EXTI_IT));
	/* */
	enablestatus = (u32)(EXTIx->IES & EXTI_IT);
	/* */
	if (((u32)(EXTIx->IF & EXTI_IT) != (u32)RESET) && (enablestatus != (u32)RESET))
	{
		/* */
		bitstatus = SET;
	}
	else
	{
		/* */
		bitstatus = RESET;
	}
	/* */
	return  bitstatus;
}


/**
  * @}
  */

